package by.grsu.perovskij.page;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import by.grsu.perovskij.dao.ScheduleRecordDao;
import by.grsu.perovskij.entity.ScheduleRecord;
import by.grsu.perovskij.tools.TimeHelper;

@SuppressWarnings("serial")
public class ListScheduleRecordsPage extends BasePage {
	@SpringBean
	private ScheduleRecordDao scheduleRecordDao;

	public ListScheduleRecordsPage() {
		super();

		final List<ScheduleRecord> scheduleRecords = scheduleRecordDao
				.findAll();

		add(new ListView<ScheduleRecord>("list", scheduleRecords) {

			@Override
			protected void populateItem(final ListItem<ScheduleRecord> item) {
				final ScheduleRecord scheduleRecord = item.getModelObject();
				item.add(new Label("departureStation", scheduleRecord
						.getDepartureStation()));
				item.add(new Label("arrivalStation", scheduleRecord
						.getArrivalStation()));
				item.add(new Label("departureDate", TimeHelper
						.getReadableDate(scheduleRecord.getDepartureDate())));
				item.add(new Label("arrivalDate", TimeHelper
						.getReadableDate(scheduleRecord.getArrivalDate())));
				item.add(new Label("trainId", String.valueOf(scheduleRecord
						.getTrain().getId())));
			}
		});

	}
}
